package com.evildog.workspace.system.application.feign;

import com.evildog.workspace.common.result.Result;
import com.evildog.workspace.common.result.ResultGenerator;
import com.evildog.workspace.system.api.feign.ApiPermissionClient;
import com.evildog.workspace.system.api.vo.ApiPermissionVO;
import com.evildog.workspace.system.application.convert.ApiPermissionConvert;
import com.evildog.workspace.system.application.service.ApiPermissionService;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * ApiPermissionClient
 * </p>
 *
 * gateway使用
 *
 * @author evildog
 * @since 2020-07-18
 */
@RestController
@RequestMapping(ApiPermissionClient.API_PREFIX)
@AllArgsConstructor
@Api(tags = "ApiPermission 相关接口")
public class ApiPermissionClientImpl implements ApiPermissionClient {

    private ApiPermissionService apiPermissionService;

    @Override
    @GetMapping("/all")
    public Result<List<ApiPermissionVO>> getAllPermissions() {
        return ResultGenerator.success(
                ApiPermissionConvert.INSTANCE.convertFeignList(apiPermissionService.getAllPermissions())
        );
    }

    @Override
    @GetMapping("/user")
    public Result<List<ApiPermissionVO>> getUserPermissions(Long userId) {
        return ResultGenerator.success(
                ApiPermissionConvert.INSTANCE.convertFeignList(apiPermissionService.getUserPermissions(userId))
        );
    }
}

